<?php require_once("../../includes_view/header.php"); ?>
<?php 
	$acao = "GRID"; 
	require_once("regras/controlador/controleacessoController.php"); 
?>
<script type="text/javascript">			
	$(document).ready(function(){
        
		$("#ddlUsuarios").change(function(){ 			
			if($("#ddlUsuarios option:selected").val() > 0){
				window.location = "controleacesso.php?codigo="+$("#ddlUsuarios option:selected").val();
			}
		});
    });
</script>
<div id="sistema">
	<div id="migalhas">
    	<a class="mig1">Configuraçoes</a>
      	<a class="mig2">Controle de Acesso</a>      	
    </div>
    <div id="pesquisa"></div>
    <br>
    <?php if(isset($class) and isset($mensagem)){ ?>  
    <div id="mensagens" class="<?=$class?>"><?php echo $mensagem; ?></div>    
    <?php } ?>
    <div id="grid">
    	<form name="frmPermissao" id="frmPermissao" method="POST">
    	<div>
        	<label>Usuários</label><br>
            <select name="ddlUsuarios" id="ddlUsuarios" class="formularioDDL">
            	<option value="0">Selecione Usuario</option>
                <?php 
					foreach($usuarios as $usuario){ 
						$selecionado = "";
						if($codigoUsuario == $usuario["id"]){
							$selecionado = "selected='selected'";
						}
				?>
                	<option value="<?=$usuario["id"]?>" <?=$selecionado?>><?=utf8_encode($usuario["nome"])?></option>
                <?php } ?>
            </select>
        </div>
        <table>
        	<thead>
            	<tr>
                    <td>&nbsp;</td>
                    <td>Categoria</td>
                    <td>Menu</td>
                    <td>&nbsp;</td>
                </tr>
            </thead>
            <tbody>
            	<?php foreach($itensMenu as $item){ $i=0; ?>
            	<tr>                    
                    <td><input type='checkbox' name="cbxcategoria[]" id="cbxcategoria_<?=$i?>" value="<?=$item["id"]?>" <?php if(in_array($item["id"],$permissaoUsuario)) echo "checked"; ?>></td>
                    <td><?=utf8_encode($item["categoria"])?></td>
                    <td><?=utf8_encode($item["menu"])?></td>
                    <td>&nbsp;</td>
                </tr>   
                <?php $i++; }?>            
            </tbody>
            <tfoot>
            	<tr>
                	<td>&nbsp;</td>
                    <td>Categoria</td>
                    <td>Menu</td>
                    <td>&nbsp;</td>
                </tr>
            </tfoot>
        </table>
        <br>
        <div class="linha">
            <div class='esquerda'>  
                <input type="hidden" name="hdCodigo" id="hdCodigo" value="<?=$codigoUsuario?>"> 
                <?php if($codigoUsuario > 0){ ?>        	
                <input type="submit" name="btnAtualizar" id="btnAtualizar" value="atualizar" class="button">
                <? } ?>
            </div>            
        </div> 
    </div>    
    </form>
</div>
<?php require_once("../../includes_view/footer.php"); ?>